package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.AuthLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.user.service.UserListenProcessService;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

@Tag(name = "用户声音播放进度管理接口")
@RestController
@RequestMapping("/api/user")
@SuppressWarnings({"all"})
public class UserListenProcessApiController {

	@Autowired
	private UserListenProcessService userListenProcessService;

	@AuthLogin
	@GetMapping("/userListenProcess/getLatelyTrack")
	public Result<Map<String, Long>> getLatelyTrack() {
		Long userId = AuthContextHolder.getUserId();
		Map<String, Long> resultMap = userListenProcessService.getLatelyTrack(userId);
		return Result.ok(resultMap);
	}

	@AuthLogin(required = false)
	@PostMapping("/userListenProcess/updateListenProcess")
	public Result updateListenProcess(@RequestBody UserListenProcessVo userListenProcessVo) {
		Long userId = AuthContextHolder.getUserId();
		if (userId != null) {
			userListenProcessService.updateListenProcess(userId, userListenProcessVo);
		}
		return Result.ok();
	}

	@AuthLogin(required = false)
	@GetMapping("/userListenProcess/getTrackBreakSecond/{trackId}")
	public Result<BigDecimal> getTrackBreakSecond(@PathVariable Long trackId) {

		Long userId = AuthContextHolder.getUserId();
		if (userId != null) {
			BigDecimal breakSecond = userListenProcessService.getTrackBreakSecond(userId, trackId);
			return Result.ok(breakSecond);
		}
		return Result.ok(new BigDecimal(0));
	}

}

